
function SubmitOrder(topay) {


	if(localStorage.usertoken==undefined){
		console.log("请登陆") 
	}


if(topay== "Wechat")
{


$.ajax({
  type:"post",    contentType: "application/json", //必须有
  url: 'http://igo.vrdete.com/client/orderinfo/generateorder',
  
 			 headers:{'usertoken':localStorage.usertoken},	  

 data:"{'orderinfo':{'orderAddress':'深圳罗湖','paymentMethod':'Wechat','orderAdcode':'440301'},"
 +"'commodity':[{'commodityNumber':'123','buyAmount':'1'},{'commodityNumber':'456','buyAmount':'1'}],"
 +"'incidental':[{'commodityNumber':'123','buyAmount':'1'},{'commodityNumber':'456','buyAmount':'1'}]}",
 

 
 
			success:function(obj){
				var data = JSON.parse(obj);
				
				console.log(data.dataResultObj.dataResultObj);



if (typeof WeixinJSBridge == "undefined"){
   if( document.addEventListener ){
       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
   }else if (document.attachEvent){
       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
   }
}else{
	
	$("#ordernumber").val(data.dataResultMap.orderNumbenr)
	
	$("#restnumber").val(data.dataResultMap.orderNumbenr)
	$("#tko").val(data.dataResultMap.orderNumbenr)
	
	 onBridgeReady(data);
	
	/*if(data.htmlState=="Success"){
		
	}
	else{
		  console.log(
		  "error")
	}*/

   
}






			},
			error:function(xhr,type,errorThrown){
				//异常处理；
				console.log(type);
			}
         });






	
		
		
}

if(topay== "AliPay"){
	
	

$.ajax({
  type:"post",    contentType: "application/json", //必须有
  url: 'http://igo.vrdete.com/client/orderinfo/generateorder',
    dataType:"json",
 			 headers:{'usertoken':localStorage.usertoken},	  

 data:"{'orderinfo':{'orderAddress':'深圳罗湖','paymentMethod':'AliPay','orderAdcode':'440301'},"
 +"'commodity':[{'commodityNumber':'123','buyAmount':'1'},{'commodityNumber':'456','buyAmount':'1'}],"
 +"'incidental':[{'commodityNumber':'123','buyAmount':'1'},{'commodityNumber':'456','buyAmount':'1'}]}",
 

 
 
			success:function(data){
		
   //data = eval('('+data+')');
      var result = data.rows[0];
      $('#main-tab').tabs('close',title);
      openPage(title,'',baseUrl+result.moUrl,null);




			},
			error:function(xhr,type,errorThrown){
				//异常处理；
				console.log(type);
			}
         });
}





}



function RSubmitOrder () {



	if(localStorage.usertoken==undefined){
		console.log("请登陆") 
	}


else
{


var orderNumberdsds = $("#restnumber").val();
$.ajax({
  type:"post",    contentType: "application/json", //必须有
  url: 'http://igo.vrdete.com/client/orderinfo/againneworder',
  			 headers:{'usertoken':localStorage.usertoken},	  
  
 
 data:"{'orderNumber':'"+orderNumberdsds+"'}",
 
			success:function(data){
				console.log(data.dataResultObj.dataResultObj);



if (typeof WeixinJSBridge == "undefined"){
   if( document.addEventListener ){
       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
   }else if (document.attachEvent){
       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
   }
}else{
	
		 onBridgeReady(data);
	

   
}

			},
			error:function(xhr,type,errorThrown){
				//异常处理；
				console.log(type);
			}
         });






	
		
		
}
}



function wechatrefund() {
	var a =$("#tko").val();
	var b  =$("#tkj").val();
	var c =$("#tkz").val();
	$.ajax({
  type:"post",    contentType: "application/json", //必须有
  url: 'http://igo.vrdete.com/api/wechat/pay/wechatrefund',
data:"{'orderNumber':'"+a+"','refundFee':'"+b+"','paymentAmount':'"+c+"'}",
  success: function(data){
                 console.log(data)   
$("#ordersts").val(data.htmlState)				 
            } 
         });
	
}









function onBridgeReady(data){
	console.log(data);
   WeixinJSBridge.invoke(
       'getBrandWCPayRequest', {
           "appId":data.dataResultObj.dataResultObj.appId,     //公众号名称，由商户传入     
           "timeStamp":data.dataResultObj.dataResultObj.timeStamp,         //时间戳，自1970年以来的秒数     
           "nonceStr":data.dataResultObj.dataResultObj.nonceStr, //随机串     
           "package":data.dataResultObj.dataResultObj.prepayId,     
           "signType":"MD5",         //微信签名方式：     
           "paySign":data.dataResultObj.dataResultObj.paySign //微信签名 
       },
       function(res){     
           if(res.err_msg == "get_brand_wcpay_request:ok" ) {
			  	$("#ordersts").val("支付成功")
		
			  
			   
			   }  
           else if (res.err_msg == "get_brand_wcpay_request:cancel") {
  	$("#ordersts").val("已取消支付")		
		
		}    // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。 
       }




   ); 
}